import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Test {
}
class Solution {
    public int countPoints(String rings) {
        int ans = 0;
        Set<Integer> set = new HashSet<>();
        List<List<Character>> list = new ArrayList<>();
        for(int i=0; i<10; i++){
            list.add(new ArrayList<>());
        }
        for(int i=0; i<rings.length(); i+=2){
            int index = rings.charAt(i+1)-'0';
            if(isValid(list.get(index),rings.charAt(i)))
                list.get(index).add(rings.charAt(i));
            if(list.get(index).size()==3&&!set.contains(index)){
                set.add(index);
                ans++;
            }
        }
        return ans;
    }
    public boolean isValid(List<Character> list, char i){
        for(char x : list){
            if(i==x){
                return false;
            }
        }
        return true;
    }
}
